<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/view/common/tag.jsp" %>
<html>
<head>
    <meta charset="utf-8">
    <title>FUN登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="stylesheet" href="${baseurl}/lib/layui/css/layui.css">
    <link rel="stylesheet" href="${baseurl}/css/portal/global.css">
</head>
<body>

<jsp:include page="header.jsp"></jsp:include>

<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <ul class="layui-tab-title">
                <li class="layui-this">登录</li>
                <li><a href="${baseurl}/portal/register">注册</a></li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form layui-form-pane">
                        <form method="post">
                            <div class="layui-form-item">
                                <label for="loginName" class="layui-form-label">登录名</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="loginName" name="loginName" required lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="password" class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="password" name="password" required lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="randomImage" class="layui-form-label">人类验证</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="randomImage" name="randomImage" required lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <a href="javascript:void(0);" title="点击更换验证码">
                                        <img src="${baseurl}/portal/getRandomImage" class="imgcode" style="width: 110px;height: 38px"/>
                                    </a>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn" lay-filter="login" lay-submit>立即登录</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="fly-footer" style="margin-top: 23%">
    <p>FUN 2021 &copy; FUN.com 出品</p>
</div>

<script type="text/javascript" src="${baseurl}/lib/layui/layui.js"></script>
<script type="text/javascript" src="${baseurl}/lib/layui_custom/Hlayui.js"></script>
<script>
    layui.use(['jquery','layer','form','layerCustom'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form  = layui.form;
        var layerCustom  = layui.layerCustom;
        //验证码切换
        $('.imgcode').click(function () {
            var url = BaseUrl + "portal/getRandomImage?s=" + Math.random();
            $(".imgcode").attr("src", url);
        });

        /*表单提交*/
        form.on('submit(login)', function (data) {
            var url = BaseUrl + 'user/login';
            //登录
            $.post(url, data.field, function (result) {
                if (result.success) {
                    layerCustom.greenLaughMsg(result.msg,function () {
                        //跳转到主页面
                        window.top.location.href = BaseUrl+"portal/indexNew";
                    })
                } else {
                    //刷新验证码
                    var url = BaseUrl + "portal/getRandomImage?s=" + Math.random();
                    layerCustom.redCryMsg(result.msg);
                    $(".imgcode").attr("src", url);
                }
            }, 'json');

            return false;
        });
    })
</script>

</body>
</html>
